﻿#region Copyrights Notice
//©2010 Microsoft Corporation. All rights reserved.
#endregion

#region usings
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
#endregion

namespace Microsoft.InformationSecurity.CISF.SecurityPortal.Business.Widget
{
    public static class WidgetControlFactory
    {
        public static UserControl CreateControlHost(TemplateControl host)
        {
            UserControl currentControl = host.LoadControl("Widgets\\MasterControls\\WidgetHost.ascx") as UserControl;
            return currentControl;
        }

        public static UserControl CreateWidget(TemplateControl host, int nControlId, string relativePath)
        {
            string strPath = "..\\" + relativePath;
            UserControl currentControl;
            try
            {
                currentControl = host.LoadControl(strPath) as UserControl;
                currentControl.ID = "Widget" + nControlId.ToString();
                return currentControl;
            }
            catch
            {
                //do catch logic here
            }

            strPath = "\\" + relativePath;

            try
            {
                currentControl = host.LoadControl(strPath) as UserControl;
                currentControl.ID = "Widget" + nControlId.ToString();
                return currentControl;
            }
            catch
            {
                //catch logic here
            }

            return null;
        }
    }
}
